<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      应用程序版本查询
      <small>注意环境选择</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
      <li class="active">Here</li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">

    <div class="row">
      <div class="col-xs-12">

        <%= form_tag '/deploy/view_version/%s' % @app.id do %>
            <div class="box box-primary">
              <div class="box-header">
                <h3 class="box-title">应用名：<%= @app.name %></h3>
              </div>
              <!-- /.box-header -->
              <div class="box-body">
                <!-- radio -->
                <div class="form-group">
                  <label>环境选择</label>
                  <div class="radio">
                    <label>
                      <input type="radio" name="env" value="<%= DeployToolUtil.env_test%>" checked>
                      <%= DeployToolUtil.env_test%>
                    </label>
                  </div>
                  <% if current_user.can_deploy_jicheng? %>
                      <div class="radio">
                        <label>
                          <input type="radio" name="env" value="<%= DeployToolUtil.env_jicheng%>">
                          <%= DeployToolUtil.env_jicheng%>
                        </label>
                      </div>
                  <%end%>
                  <% if current_user.can_deploy_predeploy? %>
                      <div class="radio">
                        <label>
                          <input type="radio" name="env" value="<%= DeployToolUtil.env_pre%>">
                          <%= DeployToolUtil.env_pre%>
                        </label>
                      </div>
                  <% end %>
                  <% if current_user.can_deploy_huidu? %>
                      <div class="radio">
                        <label>
                          <input type="radio" name="env" value="<%= DeployToolUtil.env_huidu%>">
                          <%= DeployToolUtil.env_huidu%>
                        </label>
                      </div>
                  <% end %>
                  <% if current_user.can_deploy_production?%>
                      <div class="radio">
                        <label>
                          <input type="radio" name="env" value="<%= DeployToolUtil.env_production%>">
                          <%= DeployToolUtil.env_production%>
                        </label>
                      </div>
                  <% end %>
                </div>
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">版本查询</button>
              </div>
            </div>
            <!-- /.box -->
        <% end %>
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </section>
  <!-- /.content -->
</div><!-- /.content-wrapper -->

<script type="text/javascript">
  isFirstClick = true
  $('.btn-primary').click(function () {
    //生产环境部署要求额外确认
    if ($(".radio").find("input:checked").val() == '生产') {
      var re = window.confirm('该操作会部署生产环境，确认继续吗？')
      if (!re) {
        return false
      }
      re = window.confirm('该操作会部署生产环境，确认继续吗？')
      if (!re) {
        return false
      }
    }
    //通过js防止重复提交
    if (isFirstClick) {
      isFirstClick = false
    } else {
      return false
    }
  })

  //#ctrl+v自动复制剪切板中的版本信息
  $('input').keyup(function () {
    var data = $(this).val();
    if (data.split(" ").length == 2) {
      var data_array = data.split(" ");
      svn_address = data_array[0].replace(/\t+/, "")
      revision = data_array[1].replace(/\t+/, "")
      //验证数据是否符合格式，如果符合格式，自动赋值到2个input中
      if (svn_address.match(/^http:|svn:/)
          && revision.match(/^\d+$/)) {
        $('input[name="svn_address"]').val(svn_address)
        $('input[name="svn_revision"]').val(revision)
      }
    }
  })
</script>
